//Constructor is with baseUrl

package PotentialGraduandChecking;

import org.junit.*;
import org.openqa.selenium.*;
import org.openqa.selenium.support.FindBy;

public class LoginPage {
	
	@FindBy(id = "MUA_CODE.DUMMY.MENSYS")
	private WebElement username;
	
	@FindBy(id = "PASSWORD.DUMMY.MENSYS")
	private WebElement password;
	
	@FindBy(name = "BP101.DUMMY_B.MENSYS.1")
	private WebElement LoginButton;
	
	@FindBy(id = "SM_MENU")
	private WebElement ConsolePageMenu;
	

	@Test
	// Login successfully
	public ConsolePage LoginSuccess(String usr, String pwd) throws Exception {
	   
		username.sendKeys(usr);
		password.sendKeys(pwd);
		LoginButton.click();
	    
	    long end = System.currentTimeMillis() + 12000;
	    while (System.currentTimeMillis() < end) {
	        

	        // If specific object displayed then go to next step.
	        if (ConsolePageMenu.isDisplayed()) {
	        	break;
	        }
	    }
	    
	    return new ConsolePage();
	    
	}
	//Login failed
	public LoginFailPage LoginFail(String usr, String pwd) throws Exception {
		       
		username.sendKeys(usr);
		password.sendKeys(pwd);
		LoginButton.click();
	    
	    long end = System.currentTimeMillis() + 5000;
	    while (System.currentTimeMillis() < end) {
	        

	        // If specific object displayed then go to next step.
	        if (LoginButton.isDisplayed()) {
	        	break;
	        }
	    }
	
	    return new LoginFailPage();
	    
	}

}
